package com.sandking.db.bean;

import com.sandking.tools.SK_Map;
import java.util.ArrayList;
import com.alibaba.fastjson.JSON;
import java.util.Map;
import com.sandking.db.cache.FwqtjbbCache;
import com.sandking.io.SK_OutputStream;
import java.util.List;
import com.sandking.io.SK_InputStream;
import java.io.ByteArrayInputStream;
import java.util.HashMap;
import java.io.ByteArrayOutputStream;

/**
 * 服务器统计报表
 */
public class Fwqtjbb {

	public static final String TABLENAME = "服务器统计报表";
	public static final String CLASSNAME = "Fwqtjbb"; 
	/**
	 * 需要更新字段集
	 */
	private Map<String, Object> updateColumns;

	/** id */
	private int id;
	
	/** 服务器id */
	private int fwqid;
	
	/** 服务器名称 */
	private String fwqmc;
	
	/** 渠道 */
	private String qd;
	
	/** 总注册 */
	private int zzc;
	
	/** 当日注册 */
	private int drzc;
	
	/** 当日登陆 */
	private int drdl;
	
	/** 充值金额 */
	private int czje;
	
	/** 充值人数 */
	private int czrs;
	
	/** 新增充值金额 */
	private int xzczje;
	
	/** 新增充值人数 */
	private int xzczrs;
	
	
	public Fwqtjbb() {
		super();
	}
	
	public Fwqtjbb(int id, int fwqid, String fwqmc, String qd, int zzc, int drzc, int drdl, int czje, int czrs, int xzczje, int xzczrs) {
		super();
		this.id = id;
		this.fwqid = fwqid;
		this.fwqmc = fwqmc;
		this.qd = qd;
		this.zzc = zzc;
		this.drzc = drzc;
		this.drdl = drdl;
		this.czje = czje;
		this.czrs = czrs;
		this.xzczje = xzczje;
		this.xzczrs = xzczrs;
	}
	
	public Map<String, Object> getUpdateColumns() {
		if(updateColumns == null)
			updateColumns = new HashMap<String, Object>();
		return updateColumns;
	}
	
	public int getId() {
		return id;
	}
	
	public void setId(int id) {
		this.id = id;
		addUpdateColumn("id",id);
	}
	
	public void changeIdWith(int id){
		this.id += id;
		setId(this.id);
	}
	
	public void changeIdWithMin(int id,int min){
		this.id += id;
		this.id = this.id < min ? min : this.id;
		setId(this.id);
	}
	
	public void changeIdWithMax(int id,int max){
		this.id += id;
		this.id = this.id > max ? max : this.id;
		setId(this.id);
	}
	
	public void changeIdWithMaxMin(int id,int max,int min){
		this.id += id;
		this.id = this.id < min ? min : this.id;
		this.id = this.id > max ? max : this.id;
		setId(this.id);
	}	
	public int getFwqid() {
		return fwqid;
	}
	
	public void setFwqid(int fwqid) {
		this.fwqid = fwqid;
		addUpdateColumn("服务器id",fwqid);
	}
	
	public void changeFwqidWith(int fwqid){
		this.fwqid += fwqid;
		setFwqid(this.fwqid);
	}
	
	public void changeFwqidWithMin(int fwqid,int min){
		this.fwqid += fwqid;
		this.fwqid = this.fwqid < min ? min : this.fwqid;
		setFwqid(this.fwqid);
	}
	
	public void changeFwqidWithMax(int fwqid,int max){
		this.fwqid += fwqid;
		this.fwqid = this.fwqid > max ? max : this.fwqid;
		setFwqid(this.fwqid);
	}
	
	public void changeFwqidWithMaxMin(int fwqid,int max,int min){
		this.fwqid += fwqid;
		this.fwqid = this.fwqid < min ? min : this.fwqid;
		this.fwqid = this.fwqid > max ? max : this.fwqid;
		setFwqid(this.fwqid);
	}	
	public String getFwqmc() {
		return fwqmc;
	}
	
	public void setFwqmc(String fwqmc) {
		this.fwqmc = fwqmc;
		addUpdateColumn("服务器名称",fwqmc);
	}
	
	public String getQd() {
		return qd;
	}
	
	public void setQd(String qd) {
		this.qd = qd;
		addUpdateColumn("渠道",qd);
	}
	
	public int getZzc() {
		return zzc;
	}
	
	public void setZzc(int zzc) {
		this.zzc = zzc;
		addUpdateColumn("总注册",zzc);
	}
	
	public void changeZzcWith(int zzc){
		this.zzc += zzc;
		setZzc(this.zzc);
	}
	
	public void changeZzcWithMin(int zzc,int min){
		this.zzc += zzc;
		this.zzc = this.zzc < min ? min : this.zzc;
		setZzc(this.zzc);
	}
	
	public void changeZzcWithMax(int zzc,int max){
		this.zzc += zzc;
		this.zzc = this.zzc > max ? max : this.zzc;
		setZzc(this.zzc);
	}
	
	public void changeZzcWithMaxMin(int zzc,int max,int min){
		this.zzc += zzc;
		this.zzc = this.zzc < min ? min : this.zzc;
		this.zzc = this.zzc > max ? max : this.zzc;
		setZzc(this.zzc);
	}	
	public int getDrzc() {
		return drzc;
	}
	
	public void setDrzc(int drzc) {
		this.drzc = drzc;
		addUpdateColumn("当日注册",drzc);
	}
	
	public void changeDrzcWith(int drzc){
		this.drzc += drzc;
		setDrzc(this.drzc);
	}
	
	public void changeDrzcWithMin(int drzc,int min){
		this.drzc += drzc;
		this.drzc = this.drzc < min ? min : this.drzc;
		setDrzc(this.drzc);
	}
	
	public void changeDrzcWithMax(int drzc,int max){
		this.drzc += drzc;
		this.drzc = this.drzc > max ? max : this.drzc;
		setDrzc(this.drzc);
	}
	
	public void changeDrzcWithMaxMin(int drzc,int max,int min){
		this.drzc += drzc;
		this.drzc = this.drzc < min ? min : this.drzc;
		this.drzc = this.drzc > max ? max : this.drzc;
		setDrzc(this.drzc);
	}	
	public int getDrdl() {
		return drdl;
	}
	
	public void setDrdl(int drdl) {
		this.drdl = drdl;
		addUpdateColumn("当日登陆",drdl);
	}
	
	public void changeDrdlWith(int drdl){
		this.drdl += drdl;
		setDrdl(this.drdl);
	}
	
	public void changeDrdlWithMin(int drdl,int min){
		this.drdl += drdl;
		this.drdl = this.drdl < min ? min : this.drdl;
		setDrdl(this.drdl);
	}
	
	public void changeDrdlWithMax(int drdl,int max){
		this.drdl += drdl;
		this.drdl = this.drdl > max ? max : this.drdl;
		setDrdl(this.drdl);
	}
	
	public void changeDrdlWithMaxMin(int drdl,int max,int min){
		this.drdl += drdl;
		this.drdl = this.drdl < min ? min : this.drdl;
		this.drdl = this.drdl > max ? max : this.drdl;
		setDrdl(this.drdl);
	}	
	public int getCzje() {
		return czje;
	}
	
	public void setCzje(int czje) {
		this.czje = czje;
		addUpdateColumn("充值金额",czje);
	}
	
	public void changeCzjeWith(int czje){
		this.czje += czje;
		setCzje(this.czje);
	}
	
	public void changeCzjeWithMin(int czje,int min){
		this.czje += czje;
		this.czje = this.czje < min ? min : this.czje;
		setCzje(this.czje);
	}
	
	public void changeCzjeWithMax(int czje,int max){
		this.czje += czje;
		this.czje = this.czje > max ? max : this.czje;
		setCzje(this.czje);
	}
	
	public void changeCzjeWithMaxMin(int czje,int max,int min){
		this.czje += czje;
		this.czje = this.czje < min ? min : this.czje;
		this.czje = this.czje > max ? max : this.czje;
		setCzje(this.czje);
	}	
	public int getCzrs() {
		return czrs;
	}
	
	public void setCzrs(int czrs) {
		this.czrs = czrs;
		addUpdateColumn("充值人数",czrs);
	}
	
	public void changeCzrsWith(int czrs){
		this.czrs += czrs;
		setCzrs(this.czrs);
	}
	
	public void changeCzrsWithMin(int czrs,int min){
		this.czrs += czrs;
		this.czrs = this.czrs < min ? min : this.czrs;
		setCzrs(this.czrs);
	}
	
	public void changeCzrsWithMax(int czrs,int max){
		this.czrs += czrs;
		this.czrs = this.czrs > max ? max : this.czrs;
		setCzrs(this.czrs);
	}
	
	public void changeCzrsWithMaxMin(int czrs,int max,int min){
		this.czrs += czrs;
		this.czrs = this.czrs < min ? min : this.czrs;
		this.czrs = this.czrs > max ? max : this.czrs;
		setCzrs(this.czrs);
	}	
	public int getXzczje() {
		return xzczje;
	}
	
	public void setXzczje(int xzczje) {
		this.xzczje = xzczje;
		addUpdateColumn("新增充值金额",xzczje);
	}
	
	public void changeXzczjeWith(int xzczje){
		this.xzczje += xzczje;
		setXzczje(this.xzczje);
	}
	
	public void changeXzczjeWithMin(int xzczje,int min){
		this.xzczje += xzczje;
		this.xzczje = this.xzczje < min ? min : this.xzczje;
		setXzczje(this.xzczje);
	}
	
	public void changeXzczjeWithMax(int xzczje,int max){
		this.xzczje += xzczje;
		this.xzczje = this.xzczje > max ? max : this.xzczje;
		setXzczje(this.xzczje);
	}
	
	public void changeXzczjeWithMaxMin(int xzczje,int max,int min){
		this.xzczje += xzczje;
		this.xzczje = this.xzczje < min ? min : this.xzczje;
		this.xzczje = this.xzczje > max ? max : this.xzczje;
		setXzczje(this.xzczje);
	}	
	public int getXzczrs() {
		return xzczrs;
	}
	
	public void setXzczrs(int xzczrs) {
		this.xzczrs = xzczrs;
		addUpdateColumn("新增充值人数",xzczrs);
	}
	
	public void changeXzczrsWith(int xzczrs){
		this.xzczrs += xzczrs;
		setXzczrs(this.xzczrs);
	}
	
	public void changeXzczrsWithMin(int xzczrs,int min){
		this.xzczrs += xzczrs;
		this.xzczrs = this.xzczrs < min ? min : this.xzczrs;
		setXzczrs(this.xzczrs);
	}
	
	public void changeXzczrsWithMax(int xzczrs,int max){
		this.xzczrs += xzczrs;
		this.xzczrs = this.xzczrs > max ? max : this.xzczrs;
		setXzczrs(this.xzczrs);
	}
	
	public void changeXzczrsWithMaxMin(int xzczrs,int max,int min){
		this.xzczrs += xzczrs;
		this.xzczrs = this.xzczrs < min ? min : this.xzczrs;
		this.xzczrs = this.xzczrs > max ? max : this.xzczrs;
		setXzczrs(this.xzczrs);
	}	
	
	public void addUpdateColumn(String key, Object val) {
		Map<String, Object> map = getUpdateColumns();
		if (map == null)
			return;
		map.put(key, val);
	}
	
	public void clearUpdateColumn() {
		Map<String, Object> map = getUpdateColumns();
		if (map == null)
			return;
		map.clear();
	}
	
	public Map<String, Object> toMap(){
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("id", this.id);
        result.put("fwqid", this.fwqid);
        result.put("fwqmc", this.fwqmc);
        result.put("qd", this.qd);
        result.put("zzc", this.zzc);
        result.put("drzc", this.drzc);
        result.put("drdl", this.drdl);
        result.put("czje", this.czje);
        result.put("czrs", this.czrs);
        result.put("xzczje", this.xzczje);
        result.put("xzczrs", this.xzczrs);
        return result;
    }
    
    public String toString(){
        return toMap().toString();
    }
    
    public String toJson(){
    	return JSON.toJSONString(toMap());
    }
    
    /**
     * 数据库源字段Map
     */
    public Map<String, Object> toColumnNameMap(){
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("id", this.id);
        result.put("服务器id", this.fwqid);
        result.put("服务器名称", this.fwqmc);
        result.put("渠道", this.qd);
        result.put("总注册", this.zzc);
        result.put("当日注册", this.drzc);
        result.put("当日登陆", this.drdl);
        result.put("充值金额", this.czje);
        result.put("充值人数", this.czrs);
        result.put("新增充值金额", this.xzczje);
        result.put("新增充值人数", this.xzczrs);
        return result;
    }
    
    public String toColumnNameString(){
        return toColumnNameMap().toString();
    }
    
    public byte[] toBytes() throws Exception {
    	try (ByteArrayOutputStream out = new ByteArrayOutputStream();) {
		    SK_OutputStream.writeInt(out,this.id);
		    SK_OutputStream.writeInt(out,this.fwqid);
		    SK_OutputStream.writeString(out,this.fwqmc);
		    SK_OutputStream.writeString(out,this.qd);
		    SK_OutputStream.writeInt(out,this.zzc);
		    SK_OutputStream.writeInt(out,this.drzc);
		    SK_OutputStream.writeInt(out,this.drdl);
		    SK_OutputStream.writeInt(out,this.czje);
		    SK_OutputStream.writeInt(out,this.czrs);
		    SK_OutputStream.writeInt(out,this.xzczje);
		    SK_OutputStream.writeInt(out,this.xzczrs);
		    return out.toByteArray();
    	}catch (Exception e) {
            throw e;
        }
    }
    
     public static Fwqtjbb createForBytes(byte[] _byte) throws Exception {
     	try (ByteArrayInputStream in = new ByteArrayInputStream(_byte);) {
	     	Fwqtjbb fwqtjbb = new Fwqtjbb();
		    fwqtjbb.id = SK_InputStream.readInt(in,null);
		    fwqtjbb.fwqid = SK_InputStream.readInt(in,null);
		    fwqtjbb.fwqmc = SK_InputStream.readString(in,null);
		    fwqtjbb.qd = SK_InputStream.readString(in,null);
		    fwqtjbb.zzc = SK_InputStream.readInt(in,null);
		    fwqtjbb.drzc = SK_InputStream.readInt(in,null);
		    fwqtjbb.drdl = SK_InputStream.readInt(in,null);
		    fwqtjbb.czje = SK_InputStream.readInt(in,null);
		    fwqtjbb.czrs = SK_InputStream.readInt(in,null);
		    fwqtjbb.xzczje = SK_InputStream.readInt(in,null);
		    fwqtjbb.xzczrs = SK_InputStream.readInt(in,null);
		    return fwqtjbb;
    	}catch (Exception e) {
            throw e;
        }
     }
    
    /**
     * 根据list创建对象
     */
    public static List<Fwqtjbb> createForColumnNameList(List<Map<String, Object>> list){
    	List<Fwqtjbb> fwqtjbbs = new ArrayList<Fwqtjbb>();
		for (Map<String, Object> map : list) {
			fwqtjbbs.add(createForColumnNameMap(map));
		}
		return fwqtjbbs;
    }
    
    /**
     * 根据map创建对象
     */
    public static Fwqtjbb createForColumnNameMap(Map<String, Object> map){
    	Fwqtjbb obj = new Fwqtjbb();
	    obj.id = SK_Map.getInt("id", map);
	    obj.fwqid = SK_Map.getInt("服务器id", map);
	    obj.fwqmc = SK_Map.getString("服务器名称", map);
	    obj.qd = SK_Map.getString("渠道", map);
	    obj.zzc = SK_Map.getInt("总注册", map);
	    obj.drzc = SK_Map.getInt("当日注册", map);
	    obj.drdl = SK_Map.getInt("当日登陆", map);
	    obj.czje = SK_Map.getInt("充值金额", map);
	    obj.czrs = SK_Map.getInt("充值人数", map);
	    obj.xzczje = SK_Map.getInt("新增充值金额", map);
	    obj.xzczrs = SK_Map.getInt("新增充值人数", map);
        return obj;
    }
    
    /**
     * 根据list创建对象
     */
    public static List<Fwqtjbb> createForList(List<Map<String, Object>> list){
    	List<Fwqtjbb> fwqtjbbs = new ArrayList<Fwqtjbb>();
		for (Map<String, Object> map : list) {
			fwqtjbbs.add(createForColumnNameMap(map));
		}
		return fwqtjbbs;
    }
    
    /**
     * 根据map创建对象
     */
    public static Fwqtjbb createForMap(Map<String, Object> map){
    	Fwqtjbb obj = new Fwqtjbb();
	    obj.id = SK_Map.getInt("id", map);
	    obj.fwqid = SK_Map.getInt("fwqid", map);
	    obj.fwqmc = SK_Map.getString("fwqmc", map);
	    obj.qd = SK_Map.getString("qd", map);
	    obj.zzc = SK_Map.getInt("zzc", map);
	    obj.drzc = SK_Map.getInt("drzc", map);
	    obj.drdl = SK_Map.getInt("drdl", map);
	    obj.czje = SK_Map.getInt("czje", map);
	    obj.czrs = SK_Map.getInt("czrs", map);
	    obj.xzczje = SK_Map.getInt("xzczje", map);
	    obj.xzczrs = SK_Map.getInt("xzczrs", map);
        return obj;
    }
    
    public static Fwqtjbb createForJson(String json){
    	Map<String, Object> map = JSON.parseObject(json);
    	return createForMap(map);
    }
    
    public static List<Fwqtjbb> createForJson(List<String> jsons){
    	List<Fwqtjbb> fwqtjbbs = new ArrayList<Fwqtjbb>();
    	for(String json : jsons){
    		fwqtjbbs.add(createForJson(json));
    	}
    	return fwqtjbbs;
    }
    
    /** 延迟插入数据库 */
    public Fwqtjbb insert(){
    	return FwqtjbbCache.insert(this);
    }
    /** 延迟更新数据库 */
    public Fwqtjbb update(){
    	return FwqtjbbCache.update(this);
    }
    /** 延迟删除数据库 */
    public boolean delete(){
    	return FwqtjbbCache.delete(this);
    }
    /** 即时插入数据库 */
    public Fwqtjbb insertAndFlush(){
    	return FwqtjbbCache.insertAndFlush(this);
    }
    /** 即时更新数据库 */
    public Fwqtjbb updateAndFlush(){
    	return FwqtjbbCache.updateAndFlush(this);
    }
    /** 即时删除数据库 */
    public boolean deleteAndFlush(){
    	return FwqtjbbCache.deleteAndFlush(this);
    }
}